package com.donfelix.animationdemo.transitions;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.transition.Fade;
import android.transition.Slide;
import android.transition.Visibility;
import android.view.View;

import com.donfelix.animationdemo.R;
import com.donfelix.animationdemo.common.BaseDetailActivity;
import com.donfelix.animationdemo.common.Sample;
import com.donfelix.animationdemo.databinding.ActivityTransition1Binding;

/**
 * Created by Don on 2017/3/23.
 * Desc
 */

public class TransitionActivity1 extends BaseDetailActivity implements View.OnClickListener {

    private ActivityTransition1Binding binding;
    private Sample sample;

    @Override
    protected void bindData() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_transition1);
        sample = (Sample) getIntent().getExtras().getSerializable(EXTRA_SAMPLE);
        binding.setTransition1Sample(sample);
    }

    @Override
    protected void setupWindowAinimation() {
        Visibility enterTransition = buildEnterTransition();
        getWindow().setEnterTransition(enterTransition);
    }

    @Override
    protected void setupLayout() {
        binding.sample1Button1.setOnClickListener(this);
        binding.sample1Button2.setOnClickListener(this);
        binding.sample1Button3.setOnClickListener(this);
        binding.sample1Button4.setOnClickListener(this);
        binding.sample1Button5.setOnClickListener(this);
        binding.sample1Button6.setOnClickListener(this);
    }

    private Visibility buildEnterTransition() {
        Fade enterTransition = new Fade();
        enterTransition.setDuration(getResources().getInteger(R.integer.anim_duration_long));
        enterTransition.excludeTarget(R.id.square_red, true);
        return enterTransition;
    }

    private Visibility buildReturnTransition() {
        Slide returnTransition = new Slide();
        returnTransition.setDuration(getResources().getInteger(R.integer.anim_duration_long));
        return returnTransition;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.sample1_button1:
                Intent intent1 = new Intent(this, TransitionActivity2.class);
                intent1.putExtra(EXTRA_SAMPLE, sample);
                intent1.putExtra(EXTRA_TYPE, TYPE_PROGRAMMATICALLY);
                transitionTo(intent1);
                break;
            case R.id.sample1_button2:
                Intent intent2 = new Intent(this, TransitionActivity2.class);
                intent2.putExtra(EXTRA_SAMPLE, sample);
                intent2.putExtra(EXTRA_TYPE, TYPE_XML);
                transitionTo(intent2);
                break;
            case R.id.sample1_button3:
                Intent intent3 = new Intent(this, TransitionActivity3.class);
                intent3.putExtra(EXTRA_SAMPLE, sample);
                intent3.putExtra(EXTRA_TYPE, TYPE_PROGRAMMATICALLY);
                transitionTo(intent3);
                break;
            case R.id.sample1_button4:
                Intent intent4 = new Intent(this, TransitionActivity3.class);
                intent4.putExtra(EXTRA_SAMPLE, sample);
                intent4.putExtra(EXTRA_TYPE, TYPE_XML);
                transitionTo(intent4);
                break;
            case R.id.sample1_button5:
                Visibility returnTransition = buildReturnTransition();
                getWindow().setReturnTransition(returnTransition);
                finishAfterTransition();
                break;
            case R.id.sample1_button6:
                finishAfterTransition();
                break;
            default:
                break;
        }
    }
}
